PROJECT(YukiFEM)

cmake_minimum_required(VERSION 2.4)

IF(COMMAND cmake_policy)
  cmake_policy(VERSION 2.4)
  cmake_policy(SET CMP0005 OLD)
  cmake_policy(SET CMP0003 NEW)
ENDIF(COMMAND cmake_policy)

# On Visual Studio 8 MS deprecated C. This removes all 1.276E1265 security
# warnings. Copied from ITK CMakeLists.
IF(WIN32)
  IF(NOT BORLAND)
    IF(NOT CYGWIN)
      IF(NOT MINGW)
          ADD_DEFINITIONS(
            -D_CRT_FAR_MAPPINGS_NO_DEPRECATE
            -D_CRT_IS_WCTYPE_NO_DEPRECATE
            -D_CRT_MANAGED_FP_NO_DEPRECATE
            -D_CRT_NONSTDC_NO_DEPRECATE
            -D_CRT_SECURE_NO_DEPRECATE
            -D_CRT_SECURE_NO_DEPRECATE_GLOBALS
            -D_CRT_SETERRORMODE_BEEP_SLEEP_NO_DEPRECATE
            -D_CRT_TIME_FUNCTIONS_NO_DEPRECATE
            -D_CRT_VCCLRIT_NO_DEPRECATE
            -D_SCL_SECURE_NO_DEPRECATE
            )
      ENDIF(NOT MINGW)
    ENDIF(NOT CYGWIN)
  ENDIF(NOT BORLAND)
ENDIF(WIN32)


#
# Define EXECUTABLE_OUTPUT_PATH and LIBRARY_OUTPUT_PATH
#
SET(EXECUTABLE_OUTPUT_PATH 
 ${CMAKE_BINARY_DIR}/bin 
 CACHE PATH "Single output directory for building all executables."
)

SET(LIBRARY_OUTPUT_PATH 
 ${CMAKE_BINARY_DIR}/lib 
 CACHE PATH "Single output directory for building all libraries."
)

SET(CXX_TEST_PATH ${EXECUTABLE_OUTPUT_PATH}) # for tests

# Set the path to our FindXXX.cmake files
SET(CMAKE_MODULE_PATH ${YukiFEM_SOURCE_DIR}/CMakeModules)

INCLUDE(${CMAKE_ROOT}/Modules/Dart.cmake)
ENABLE_TESTING()

SET(YukiFEM_VERSION_MAJOR 1)
SET(YukiFEM_VERSION_MINOR 0)
SET(YukiFEM_VERSION_BUILD 0)
SET(YukiFEM_VERSION "${YukiFEM_VERSION_MAJOR}.${YukiFEM_VERSION_MINOR}.${YukiFEM_VERSION_BUILD}")

#----------
# wxWidgets
#----------
OPTION(USE_WXWINDOWS "If ON, Build the wxVtk extension and the wxSamples " OFF)
IF(USE_WXWINDOWS)
      
  IF(WIN32)
    SET(wxWidgets_USE_LIBS adv aui xrc xml html gl core base)
  ELSE(WIN32)
    SET(wxWidgets_USE_LIBS adv aui xrc xml html gl core base)
  ENDIF(WIN32)
   
  FIND_PACKAGE(wxWidgets2) # use the version provided by YukiFEM -> to find the aui
                           # library (advanced user interface)

IF(wxWidgets_FOUND)

    INCLUDE(${wxWidgets_USE_FILE})

    # We make the distinction between shared VTK and wxWidgets. If wxWidgets is build
    # shared, all wx-derived addons here will be shared as well.
    IF( WIN32 )
      OPTION(wxWidgets_SHARED "Is wxWidgets built with shared libraries?" OFF)
    ELSE( WIN32 )
      OPTION(wxWidgets_SHARED "Is wxWidgets built with shared libraries?" ON)
    ENDIF( WIN32 )

    IF( wxWidgets_SHARED )
      SET( wxWidgets_BUILD_SHARED_LIBS "ON" )      
      SET( wxWidgets_LIBS_STYLE "SHARED")	  
    ELSE ( wxWidgets_SHARED )
      SET( wxWidgets_BUILD_SHARED_LIBS "OFF")      
      SET( wxWidgets_LIBS_STYLE "STATIC")      
    ENDIF( wxWidgets_SHARED )

    IF(UNIX AND NOT APPLE) # our UNIX version depends on GTK-2, so find GTK-2 as well
      FIND_PACKAGE(GTK-2 REQUIRED)     
      LINK_DIRECTORIES(
      ${GTK_LINK_DIRS}
      )

      SET(wxWidgets_LIBRARIES
      ${wxWidgets_LIBRARIES}
      ${GTK_LINK_LIBS}
      )
    ENDIF(UNIX AND NOT APPLE)

  ELSE(wxWidgets_FOUND)

    MESSAGE(ERROR " wxWidgets was not found. On WIN32, check that you specified the
      correct paths. On UNIX, make sure that the correct wx-config executable was
      set and that wxWidgets was compiled with the OpenGL extension!")

  ENDIF(wxWidgets_FOUND)  

ENDIF(USE_WXWINDOWS)

# Save the compiler settings so another project can import them.
SET(YukiFEM_BUILD_SETTINGS_FILE ${YukiFEM_BINARY_DIR}/YukiFEMBuildSettings.cmake)
INCLUDE(${CMAKE_ROOT}/Modules/CMakeExportBuildSettings.cmake)
CMAKE_EXPORT_BUILD_SETTINGS(${YukiFEM_BUILD_SETTINGS_FILE})
INSTALL_FILES(/lib .cmake YukiFEMBuildSettings)


# Create the list of include directories needed for vtkINRIA3D header files.
INCLUDE(${YukiFEM_SOURCE_DIR}/YukiFEMIncludeDirectories.cmake)


INCLUDE_DIRECTORIES(
${YukiFEM_INCLUDE_DIRS_BUILD_TREE}
${YukiFEM_INCLUDE_DIRS_SOURCE_TREE}
)


CONFIGURE_FILE(${YukiFEM_SOURCE_DIR}/YukiFEMConfigure.h.in
               ${YukiFEM_BINARY_DIR}/YukiFEMConfigure.h @ONLY IMMEDIATE)

INSTALL_FILES(/include .h YukiFEMConfigure)

# To help using YukiFEM with other projects
CONFIGURE_FILE(${YukiFEM_SOURCE_DIR}/UseYukiFEM.cmake.in
               ${YukiFEM_BINARY_DIR}/UseYukiFEM.cmake COPYONLY IMMEDIATE)

SUBDIRS(
FEM
Examples
)

#
# Testing
#

FIND_PACKAGE(GoogleTest 1.5.0)


IF(BUILD_EXAMPLES)
  ADD_SUBDIRECTORY(Examples)
ENDIF(BUILD_EXAMPLES)

IF(BUILD_TESTING)
  ADD_SUBDIRECTORY(Testing)
ENDIF(BUILD_TESTING)

SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "YukiFEM")
SET(CPACK_PACKAGE_VENDOR "Summit")
SET(CPACK_PACKAGE_VERSION_MAJOR "${YukiFEM_VERSION_MAJOR}")
SET(CPACK_PACKAGE_VERSION_MINOR "${YukiFEM_VERSION_MINOR}")
SET(CPACK_PACKAGE_VERSION_PATCH "${YukiFEM_VERSION_BUILD}")
SET(CPACK_PACKAGE_INSTALL_DIRECTORY "Salmon ${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}")
SET(CPACK_SOURCE_PACKAGE_FILE_NAME
"YukiFEM-${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")

IF(WIN32)
  SET(CPACK_NSIS_DISPLAY_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY}")
  SET(CPACK_NSIS_HELP_LINK "https://code.google.com/p/jolly")
  SET(CPACK_NSIS_URL_INFO_ABOUT "http://code.google.com/p/jolly")
  SET(CPACK_NSIS_CONTACT "summit_mail@qq.com")
ENDIF(WIN32)

INCLUDE(CPack)
#
